﻿using FirebaseAdmin.Messaging;
using Microsoft.AspNetCore.Mvc;

namespace LearnNotification.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class NotificationController:ControllerBase
    {
        [HttpPost("SendNotificationAsync")]
        public async Task<IActionResult> SendNotificationAsync([FromBody]MessageRequest request)
        {
            var message = new Message()
            {
                Notification = new Notification
                {
                    Title = "Message Title",
                    Body = "Message Body"
                },
                Data = new Dictionary<string, string>()
                {
                    ["MyPhone"]="12345678900"
                },
                Token = "my maui android token"
            };

            var messaging = FirebaseMessaging.DefaultInstance;
            var result=await messaging.SendAsync(message);  

            if(!string.IsNullOrEmpty(result)) 
                return Ok("Push notification sent successfully");
            else
                return BadRequest("Push notification sent failed");
        }
    }
}
